import numpy
import numpy as np
from icecream import ic

from data_pre.data import get_char_dic

dic = get_char_dic()


def encode(s):
    dic_len = len(dic)

    res = []

    for i in s:
        temp = [0 for _ in range(dic_len)]
        temp[int(dic[i])] = 1
        res.append(temp)

    return res


def decode(y):
    dic = get_char_dic()
    res = ''

    for i in y:
        for key in dic.keys():
            if dic[key] == i:
                res += key
                break
    return res


def get_z(arr):
    for i in range(len(arr)):
        if arr[i] <= 0:
            arr[i] = int(0)
        else:
            arr[i] = int(1)

    return arr


def swap_axis(y_data):
    return numpy.swapaxes(y_data, 0, 1)
